package es.cazadoresmadridejos.beans.facade.biggame;

import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.SpringCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import es.cazadoresmadridejos.beans.manager.biggameassistance.BigGameAssistanceManager;
import es.cazadoresmadridejos.beans.manager.session.UserPreferences;
import es.cazadoresmadridejos.model.BigGameAssistance;

@Service
@RemoteProxy(name="bigGameFacade",creator=SpringCreator.class)
public class BigGameFacade {
	
	@Autowired(required=false) private UserPreferences userPreferences;
	@Autowired private BigGameAssistanceManager bigGameAssistanceManager;
	
	public void saveBigGameRecord(
			Integer deers,
			Integer wildboards,
			Integer hinds,
			String armada,
			String stand,
			Long bigGameAssistanceId
			){
		BigGameAssistance bga = bigGameAssistanceManager.get(bigGameAssistanceId);
		
		if(!bga.getPartner().getId().equals(userPreferences.getPartner().getId())){
			///mmmmm... se intenta saltar la seguridad
			return;
		}
		
		bga.setArmada(armada);
		bga.setDeers(deers);
		bga.setHinds(hinds);
		bga.setStand(stand);
		bga.setWildBoars(wildboards);
		
		bigGameAssistanceManager.save(bga);
	}

}
